package com.system.email.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;
/**
 * @Author hewei
 * @Description //TODO  消息通知发送 多线程初始化类
 * @Date 2021/6/22
 **/
@Configuration
@EnableAsync
public class TaskExecutePool {

    @Bean
    public ExecutorService executorService(){
        ExecutorService executorService = new ThreadPoolExecutor(
                5,
                100,
                100,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2000), new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName("email:"+thread.getName());
                return thread;
            }
        });
        return executorService;
    }

    @Bean
    public CountDownLatch countDownLatch(){
        return new CountDownLatch(1);
    }

}
